<?php
require  "../vendor/autoload.php";

use Menory\Unit\Validation\Validator;
use PHPUnit\Framework\TestCase;

class  ValidatorTest extends TestCase {

    private $testNumber = 0;

    /**
     * @dataProvider genData
     * @test
     */
    public function validate($data) {

        $validator = new Validator();
        $validator->setRules([
            "user_name" => "require|enum:123456,654321,123",
            "password"  => "require|rule:password"
        ]);
        $validator->setMessages([
            "user_name.require" => "sss",
            "password.require"  => "sss",
            "password.rule"     => "sss"
        ]);
        /**
         * @var \Menory\Standard\Error $err
         */
        list($data, $err) = $validator->validate($data);
        if ($err !== null) {
            $this->assertInstanceOf(\Menory\Standard\Error::class, $err);
            $this->assertEquals("sss", $err->getMessage());
            return ;
        }

        $this->assertInternalType("array", $data);

    }

    public function genData() {

        return [
            "enum" => [[
                "user_name" => "1234526",
                "password"  => "156"
            ]],
            [[
                "user_name" => "123456",
                "password"  => "1231231"
            ]],
        ];

    }

}